package com.tdw.eurekaclient.command;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.tdw.eurekaclient.dto.UserInfo;

@RestController
public class UserCommand extends HystrixCommand<UserInfo> {

	private RestTemplate restTemplate;
	private Long id;

	public UserCommand(RestTemplate restTemplate, Long id) {
		super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey
		("UserGroup")));
		this.restTemplate= restTemplate;
		this.id= id;
	}

	@Override
	protected UserInfo run() {
		return restTemplate.getForObject("http://hello-service/hystrix/getUserById?id={id}",UserInfo.class, id);
	}

	@Override
	protected String getCacheKey() {
		return String.valueOf(id);
	}

	public RestTemplate getRestTemplate() {
		return restTemplate;
	}

	public void setRestTemplate(RestTemplate restTemplate) {
		this.restTemplate = restTemplate;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	
	

}
